const app = getApp();
Page({

  /**
   * 页面的初始数据
   */
  data: {
    email:''
  },

  /**
   * 生命周期函数--监听页面加载
   */
  onLoad: function (options) {
    this.getUserInfo();
  },
  getUserInfo() {
    let that = this;
    wx.request({
      url: app.globalData.baseUrl + '/sys/getUserInfo',
      method: "GET",
      header: {
        "token": wx.getStorageSync('token')
      },
      success: function (res) {
        if (res.data.code === 200) {
          that.setData({
            email: res.data.result.email
          })
        }
      }
    })
  },
  emailInput(e){
    this.setData({
      email: e.detail
    })
  },
  save(){
    wx.request({
      url: app.globalData.baseUrl + '/sys/editUserInfo',
      method: "POST",
      data: {
        email: this.data.email
      },
      header: {
        "Content-Type": "application/json;charset=utf-8",
        "token": wx.getStorageSync('token')
      },
      success: function (res) {
        if(res.data.code === 200){
          wx.showToast({
            title: res.data.msg,
            icon: 'none',
            duration: 2000
          });
        }
        //返回上一级关闭当前页面
        wx.navigateBack({
          delta: 1
        })
      }
    })
  }


})
